import React from "react";
import {Radio} from "antd";
import useDicListByCategoryCode from "@/hooks/useDicListByCategoryCode";
import {DicValueType} from "@/global";
import {convertDicValueByType} from "@/utils/utils";

export interface DicRadioGroupProps {
  /** 字典编码 */
  dicCode: string;
  /** 字典值类型 */
  dicValueType?: DicValueType;
}

/**
 * 数据字段组件-单选框展示
 */
const DicRadioGroup = function (props: DicRadioGroupProps) {
  const {dicCode,dicValueType = DicValueType.string, ...rest} = props;
  const diclist = useDicListByCategoryCode(dicCode);

  return (
    <Radio.Group {...rest}>
      {diclist.map(p => <Radio key={p.id} value={convertDicValueByType(p.value, dicValueType)}>{p.name}</Radio>)}
    </Radio.Group>
  );
};

export default React.memo(DicRadioGroup);

